package com.jsbs.iam.user.controller;

import com.jsbs.iam.common.core.dto.Result;
import com.jsbs.iam.user.service.IamMenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author junwc
 * @Date 2022/12/8
 * @Version 1.0
 */
@RestController
@RequestMapping("/iam/user/menu")
public class IamMenuController extends BaseController{
    private static final Logger logger = LoggerFactory.getLogger(IamMenuController.class);

    @Autowired
    private IamMenuService iamMenuService;

    /**
     * 功能描述：获取IAM后端菜单列表
     * @return
     */
    @PostMapping("/query")
    public Result menuQuery() {
        logger.info("Route==>IamMenuController method=menuQuery 查询IAM后台菜单列表");
        try {
            return Result.success(iamMenuService.queryMenu());
        } catch (Exception e) {
            logger.error("Route==>IamMenuController method=menuQuery 查询IAM后台菜单列表异常：", e);
            return handleException(e);
        }
    }

    /**
     * 功能描述：根据用户编码获取IAM后端权限列表
     * @return
     */
    @PostMapping("/admin/permisson/list")
    public Result queryAdminPermissonList(@RequestParam String userCode, @RequestParam String adminRoleCode) {
        logger.info("Route==>IamMenuController method=queryAdminPermissonList 根据用户编码查询IAM后台菜单权限列表userCode：{}", userCode);
        try {
            return Result.success(iamMenuService.queryAdminPermissonList(userCode, adminRoleCode));
        } catch (Exception e) {
            logger.error("Route==>IamMenuController method=queryAdminPermissonList 根据用户编码查询IAM后台菜单权限列表异常：", e);
            return handleException(e);
        }
    }
}
